import {
  Body,
  Controller,
  Get,
  Inject,
  Param,
  Post,
  Query,
} from '@nestjs/common';
import { PoetService } from './poet.service';
import { CreateDto } from './dto/create.dto';
import { UpdateDto } from './dto/update.dto';
import { ListDto } from './dto/list.dto';
import { Public } from 'src/common/decorators/public.decorator';

@Controller('poet')
export class PoetController {
  @Inject(PoetService)
  private readonly poetService: PoetService;

  @Post('create')
  create(@Body() createDto: CreateDto) {
    return this.poetService.create(createDto);
  }

  @Get('delete')
  delete(@Param() id: number) {
    return this.poetService.delete(id);
  }

  @Post('update')
  update(@Body() updateDto: UpdateDto) {
    return this.poetService.update(updateDto);
  }

  @Get('find')
  @Public()
  info(@Query() { id }: { id: number }) {
    return this.poetService.info(id);
  }

  @Post('list')
  @Public()
  list(@Body() listDto: ListDto) {
    return this.poetService.list(listDto);
  }

  @Get('scrapeIds')
  scrapePoetIds() {
    return this.poetService.scrapePoetIds();
  }

  @Get('scrapeInfo')
  scrapePoetInfo() {
    return this.poetService.crawlContent();
  }

  @Get('test')
  test() {
    return this.poetService.processPoetsFromFile(
      'src/scrape-data/poet-content.txt',
    );
  }
}
